/**
 * Created by 55456 on 2016/4/17.
 */
var Sequelize = require("sequelize");
var config = require("../config");
var path = require("path");
var fs = require("fs");

var sequelize = new Sequelize(config.db.toString());

fs
    .readdirSync(__dirname)
    .filter(function(file){
        return (file.indexOf('.') !== 0) && (file !== 'index.js' &&  file !== 'migrate.js');
    }).forEach(function(item){
        sequelize.import(path.join(__dirname,item));
    });

// var models = sequelize.models;
// Object.keys(models).forEach(function(modelName){
//     if(models[modelName].options.hasOwnProperty("associate")){
//         models[modelName].options.associate(models);
//     }
// });

module.exports = sequelize;